package de.jabc.sib.bio.ebi;

import de.jabc.adapter.bio.ebi.Branches;
import de.jabc.adapter.bio.ebi.LightweightServiceAdapter;
import de.jabc.adapter.bio.ebi.ServiceAdapter;
import de.metaframe.jabc.framework.execution.ExecutionEnvironment;
import de.metaframe.jabc.framework.sib.annotation.SIBClass;
import de.metaframe.jabc.framework.sib.annotation.SIBStatus;
import de.metaframe.jabc.framework.sib.parameter.ContextExpression;
import de.metaframe.jabc.framework.sib.parameter.ContextKey;
import de.metaframe.jabc.sib.ServiceAdapterDescriptor;

/**
 * Calls the EBI's EMBOSS Backtranambig service. Backtranambig reads a protein
 * sequence and writes the nucleic acid sequence it could have come from. It
 * does this by using nucleotide ambiguity codes that represent all possible
 * codons for each amino acid.
 * 
 * @author naviator.dev
 * 
 */

@SIBClass("ebi-sibs/Backtranambig")
@SIBStatus("IMPLEMENTED")
public class Backtranambig extends AbstractSIB {

	/* Branches */
	public static final String[] BRANCHES = { Branches.DEFAULT, Branches.ERROR };

	/*
	 * Parameters
	 * 
	 * @param email - user email address
	 * 
	 * @param title - job title. Default is empty string.
	 * 
	 * @param codontable - Genetic code table to use.
	 * 
	 * @param sequence - Input sequence (protein).
	 * 
	 * @param result - resulting sequence.
	 */
	public ContextExpression Email = new ContextExpression("${email}",
			String.class, false);
	public ContextExpression Title = new ContextExpression("", String.class,
			false);
	public ContextExpression Codontable = new ContextExpression("",
			String.class, false);
	public ContextExpression Sequence = new ContextExpression("${sequence}",
			String.class, false);
	public ContextKey result = new ContextKey("result", ContextKey.Scope.LOCAL,
			true);

	@Override
	public String execute(ExecutionEnvironment environment) {
		try {
			return ServiceAdapter.callBacktranambig(environment, this.Email,
					this.Title, this.Codontable, this.Sequence, this.result);
		} catch (NoClassDefFoundError e) {
			return Branches.ERROR;
		}
	}

	@Override
	public ServiceAdapterDescriptor generate() {
		return new ServiceAdapterDescriptor(
				LightweightServiceAdapter.class.getName(), "callBacktranambig",
				"Email", "Title", "Codontable", "Sequence", "result");
	}

}
